<!doctype html>

<html>
<head>
  <link rel="shortcut icon" href="static/images/favicon.ico" type="image/x-icon">
  <title>progressiveemojipaletterenderer.js (Closure Library API Documentation - JavaScript)</title>
  <link rel="stylesheet" href="static/css/base.css">
  <link rel="stylesheet" href="static/css/doc.css">
  <link rel="stylesheet" href="static/css/sidetree.css">
  <link rel="stylesheet" href="static/css/prettify.css">

  <script>
     var _staticFilePath = "static/";
     var _typeTreeName = "goog";
     var _fileTreeName = "Source";
  </script>

  <script src="static/js/doc.js">
  </script>


  <meta charset="utf8">
</head>

<body onload="grokdoc.onLoad();">

<div id="header">
  <div class="g-section g-tpl-50-50 g-split">
    <div class="g-unit g-first">
      <a id="logo" href="index.html">Closure Library API Documentation</a>
    </div>

    <div class="g-unit">
      <div class="g-c">
        <strong>Go to class or file:</strong>
        <input type="text" id="ac">
      </div>
    </div>
  </div>
</div>

<div class="clear"></div>

<h2><a href="closure_goog_ui_emoji_progressiveemojipaletterenderer.js.html">progressiveemojipaletterenderer.js</a></h2>

<pre class="prettyprint lang-js">
<a name="line1"></a>// Copyright 2008 The Closure Library Authors. All Rights Reserved.
<a name="line2"></a>//
<a name="line3"></a>// Licensed under the Apache License, Version 2.0 (the &quot;License&quot;);
<a name="line4"></a>// you may not use this file except in compliance with the License.
<a name="line5"></a>// You may obtain a copy of the License at
<a name="line6"></a>//
<a name="line7"></a>//      http://www.apache.org/licenses/LICENSE-2.0
<a name="line8"></a>//
<a name="line9"></a>// Unless required by applicable law or agreed to in writing, software
<a name="line10"></a>// distributed under the License is distributed on an &quot;AS-IS&quot; BASIS,
<a name="line11"></a>// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
<a name="line12"></a>// See the License for the specific language governing permissions and
<a name="line13"></a>// limitations under the License.
<a name="line14"></a>
<a name="line15"></a>/**
<a name="line16"></a> * @fileoverview Progressive Emoji Palette renderer implementation.
<a name="line17"></a> *
<a name="line18"></a> */
<a name="line19"></a>
<a name="line20"></a>goog.provide(&#39;goog.ui.emoji.ProgressiveEmojiPaletteRenderer&#39;);
<a name="line21"></a>
<a name="line22"></a>goog.require(&#39;goog.ui.emoji.EmojiPaletteRenderer&#39;);
<a name="line23"></a>
<a name="line24"></a>
<a name="line25"></a>
<a name="line26"></a>/**
<a name="line27"></a> * Progressively renders an emoji palette. The progressive renderer tries to
<a name="line28"></a> * use img tags instead of background-image for sprited emoji, since most
<a name="line29"></a> * browsers render img tags progressively (i.e., as the data comes in), while
<a name="line30"></a> * only very new browsers render background-image progressively.
<a name="line31"></a> *
<a name="line32"></a> * @param {string} defaultImgUrl Url of the img that should be used to fill up
<a name="line33"></a> *     the cells in the emoji table, to prevent jittering. Will be stretched
<a name="line34"></a> *     to the emoji cell size. A good image is a transparent dot.
<a name="line35"></a> * @constructor
<a name="line36"></a> * @extends {goog.ui.emoji.EmojiPaletteRenderer}
<a name="line37"></a> */
<a name="line38"></a>goog.ui.emoji.ProgressiveEmojiPaletteRenderer = function(defaultImgUrl) {
<a name="line39"></a>  goog.ui.emoji.EmojiPaletteRenderer.call(this, defaultImgUrl);
<a name="line40"></a>};
<a name="line41"></a>goog.inherits(goog.ui.emoji.ProgressiveEmojiPaletteRenderer,
<a name="line42"></a>              goog.ui.emoji.EmojiPaletteRenderer);
<a name="line43"></a>
<a name="line44"></a>
<a name="line45"></a>/** @override */
<a name="line46"></a>goog.ui.emoji.ProgressiveEmojiPaletteRenderer.prototype.
<a name="line47"></a>    buildElementFromSpriteMetadata = function(dom, spriteInfo, displayUrl) {
<a name="line48"></a>  var width = spriteInfo.getWidthCssValue();
<a name="line49"></a>  var height = spriteInfo.getHeightCssValue();
<a name="line50"></a>  var x = spriteInfo.getXOffsetCssValue();
<a name="line51"></a>  var y = spriteInfo.getYOffsetCssValue();
<a name="line52"></a>  // Need this extra div for proper vertical centering.
<a name="line53"></a>  var inner = dom.createDom(&#39;img&#39;, {&#39;src&#39;: displayUrl});
<a name="line54"></a>  var el = /** @type {HTMLDivElement} */ (dom.createDom(&#39;div&#39;,
<a name="line55"></a>      goog.getCssName(&#39;goog-palette-cell-extra&#39;), inner));
<a name="line56"></a>  goog.style.setStyle(el, {
<a name="line57"></a>    &#39;width&#39;: width,
<a name="line58"></a>    &#39;height&#39;: height,
<a name="line59"></a>    &#39;overflow&#39;: &#39;hidden&#39;,
<a name="line60"></a>    &#39;position&#39;: &#39;relative&#39;
<a name="line61"></a>  });
<a name="line62"></a>  goog.style.setStyle(inner, {
<a name="line63"></a>    &#39;left&#39;: x,
<a name="line64"></a>    &#39;top&#39;: y,
<a name="line65"></a>    &#39;position&#39;: &#39;absolute&#39;
<a name="line66"></a>  });
<a name="line67"></a>
<a name="line68"></a>  return el;
<a name="line69"></a>};
<a name="line70"></a>
<a name="line71"></a>
<a name="line72"></a>/** @override */
<a name="line73"></a>goog.ui.emoji.ProgressiveEmojiPaletteRenderer.prototype.
<a name="line74"></a>    updateAnimatedPaletteItem = function(item, animatedImg) {
<a name="line75"></a>  // Just to be safe, we check for the existence of the img element within this
<a name="line76"></a>  // palette item before attempting to modify it.
<a name="line77"></a>  var img;
<a name="line78"></a>  var el = item.firstChild;
<a name="line79"></a>  while (el) {
<a name="line80"></a>    if (&#39;IMG&#39; == el.tagName) {
<a name="line81"></a>      img = /** @type {Element} */ (el);
<a name="line82"></a>      break;
<a name="line83"></a>    }
<a name="line84"></a>    el = el.firstChild;
<a name="line85"></a>  }
<a name="line86"></a>  if (!el) {
<a name="line87"></a>    return;
<a name="line88"></a>  }
<a name="line89"></a>
<a name="line90"></a>  img.width = animatedImg.width;
<a name="line91"></a>  img.height = animatedImg.height;
<a name="line92"></a>  goog.style.setStyle(img, {
<a name="line93"></a>    &#39;left&#39;: 0,
<a name="line94"></a>    &#39;top&#39;: 0
<a name="line95"></a>  });
<a name="line96"></a>  img.src = animatedImg.src;
<a name="line97"></a>};
</pre>


</body>
</html>
